var strGetQuery =document.location.search;
var id = cw.common.getQueryString(strGetQuery,'id');

$(document).ready(function(){
	cw.common.setStyle();
	$('#subImg').bind('click',subButton);
	
	cw.common.getDictByPage("FIXED_ASSETS_TYPE","","#FIXED_ASSETS_TYPE", function(obj, result, i, n){
		result.append('<option value="'+obj.TYPE_ID+'">'+obj.TYPE_NAME+'</option>');
	});
	
	cw.common.getDictByPage("FIXED_ASSETS_NATURE","","#FIXED_ASSETS_NATURE", function(obj, result, i, n){
		result.append('<option value="'+obj.TYPE_ID+'">'+obj.TYPE_NAME+'</option>');
	});
	
	
	cw.common.getUserSession(getBaseInfo,true);
	validate();
})

function getBaseInfo(){
	var url = cw.common.path + '/json?action=GET_T_FIXED_ASSETS_ACTION&FIXED_ASSETS_NO='+id;
	$.post(url,{},function(data){
		if(data.success){
			var vobj=data.root.T_FIXED_ASSETS;
			if(vobj==null||vobj==''||vobj==undefined){
				alert("该信息不存在或已被删除");
				window.history.back();
				return;
			}
			else{
				var obj = data.root.T_FIXED_ASSETS.rs[0];
				cw.common.setValue("FIXED_ASSETS_NO",id, "text");
				cw.common.setValue("FIXED_ASSETS_NAME",obj.FIXED_ASSETS_NAME, "text");
				cw.common.setValue("FIXED_ASSETS_TYPE",obj.FIXED_ASSETS_TYPE, "text");
				cw.common.setValue("BRAND",obj.BRAND, "text");
				cw.common.setValue("FIXED_ASSETS_NATURE",obj.FIXED_ASSETS_NATURE, "text");
				cw.common.setValue("REMARK",obj.REMARK, "text");
			}
		}
		else{
			alert(data.errors.errmsg);
		}
	},'json');
	
}

function subFrm(){
	var options = {
	    dataType: 'json',
    	iframe:	false,
	    success: function(data) {
	    	if(data.success){
	    		$('#subImg').bind('click',subButton);
	    		alert('已修改【'+$('#FIXED_ASSETS_NAME').val()+'】资产信息');
	      		window.location.href="base_info.html";
	      	}else{
	      		alert(data.errors.errmsg);
	      	}
	   	}
	};
	$.ajaxSetup({contentType:'application/x-www-form-urlencoded;charset=utf-8'});
    $('#frm').ajaxSubmit(options);
}

function subButton(){
	$('#subImg').unbind('click',subButton);
	return jQuery.formValidator.pageIsValid(1);
}

function validate(){
	$.formValidator.initConfig({formid:"frm",onerror:function(msg){$('#subImg').bind('click',subButton);alert(msg);},onsuccess:function(){subFrm();return false;}});
	$("#FIXED_ASSETS_NAME").formValidator({onshow:"请输入资产名称",oncorrect:"正确",onfocus:"资产名称可以由英文或简体中文组成"}).inputValidator({min:1,onerror:"资产名称必填"}).inputValidator({max:64,onerror:"资产名称中文不超过32个字，英文不超过64个字符"});
	$("#BRAND").formValidator({onshow:"请填写品牌型号",oncorrect:"正确",onfocus:"请填写品牌型号"}).inputValidator({min:1,onerror:"请填写品牌型号"}).inputValidator({max:256,onerror:"品牌型号过长"});
	$("#REMARK").formValidator({empty:true,onshow:"请输入备注",oncorrect:"正确",onfocus:"请输入备注信息"}).inputValidator({max:500,onerror:"人员备注信息中文不超过250个字，英文不超过500个字符"});
}

